<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.stone.para.IConstant"%>
<%
	String contextPath = request.getContextPath();
	String userstate = request.getParameter("userstate");
	String opernerName = request.getParameter("opernerName");
	String dw = request.getParameter("dw");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=IConstant.PROGRAEM_TITLE%></title>
        <link rel="stylesheet" href="<%=contextPath%>/ext3/resources/css/ext-all.css" type="text/css"   />
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/ext-all.js"></script>
        <script language="javascript">
            Ext.BLANK_IMAGE_URL = '<%=contextPath%>/ext3/resources/images/default/s.gif';
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'qtip';
            var cpath = '<%=contextPath%>';
		
String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
	return false;
	if(this.substr(0,str.length)==str)
	return true;
	else
	return false;
	return true;
	}
		
			Ext.onReady(function(){
			
			var tb = new Ext.Toolbar({
		    renderTo: document.all.tbar,
		    items: [
 				'->',{
			        text: '关闭',
			        icon:"<%=contextPath%>/images/banjie.png",
			        handler:function () {
			        	window.close();
			        }
			    }]
			});

			var storeSQ = new Ext.data.Store({
        		proxy:new Ext.data.HttpProxy({url:'bzUserList!getListExtTree.do?userstate=<%=userstate%>'}),
        		reader:new Ext.data.JsonReader({},['id','text','qtip','parentId']),
        		autoLoad:true,
        		listeners:{"load":function(store,records){
        							if (records != null && records != "") {
										for (var i=0; i<records.length; i++){
	       									var n = new Ext.tree.TreeNode({
                								id:records[i].data.id,
                								text:records[i].data.text,
                								qtip:records[i].data.qtip,
                								leaf:true
											});
	       									// 第一层菜单时
	       									if (records[i].data.parentId == "0") {
	       									try{
            									tree.root.appendChild(n);
            									} catch(e) {
            										alert(records[i].data.parentId);
            									}
            								// 下级菜单
	       									} else {
	       										try {
	       											tree.getNodeById(records[i].data.parentId).leaf = false;
	       											tree.getNodeById(records[i].data.parentId).appendChild(n);
	       										} catch (e) {
	       											
	       										}
	       									}
   										}
   										
   		
										// root 展开
										
										<%if ( dw != null) {%>
											tree.root.expandChildNodes();
											for(var i =0;i<tree.root.childNodes.length;i++) {
												if(tree.root.childNodes[i].id  != 'A<%=dw%>') {
													tree.root.childNodes[i].collapse(true);
												}
											}
											tree.getNodeById('A<%=dw%>').expandChildNodes();
										<%}%>
   										
   										
   										
									} 
                    			}}
    		});

            
		/* 生成Ttee,放到tree Div里面 */
 		var tree = new Ext.tree.TreePanel({
                        id:"mytree",   
                        renderTo : "tree",
                        rootVisible:false,
                        root : new Ext.tree.TreeNode({   
                    			id : "root", 
                    			draggable:false, 
                    			singleClickExpand:true, 
                    			text : "<%=IConstant.PROGRAEM_TITLE%>"
	 						}),  
                        store : storeSQ,   
                        width : 300,   
                        height : 480,
				        useArrows:true,
				        autoScroll:true,
				        animate:true,
				        containerScroll:true,
				        listeners:{"click":function(node){ 
												
								// 参照
								try {
									//alert(node.id.startWith("A"));
									if (node.id.toString().startWith("A")) {
										Ext.MessageBox.alert('提示', '请选择人员。');
										return;
									} else {
										window.opener.document.frmM.elements["<%=opernerName%>"].value = node.text;
									}
								} catch (e) {
														
								}

								window.close();	
													
                    	}}
				});
 		});      

		</script>
	</head>
	<body>
		<div id = "tbar" style="position:absolute;display:block left:0px; top:0px; width:100%; height:35px; z-index:1;"></div>
		<br>
		<div id="tree" style="position:absolute;display:block left:0px; top:35px; width:100%; height:95%; z-index:1000; overflow:auto;">
		</div>
	</body>
</html>
